package com.blue.controller.system;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import com.github.yulichang.query.MPJQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blue.common.utils.QueryWrapperUtils;
import org.springframework.web.bind.annotation.*;
import com.blue.common.utils.ConvertUtils;
import com.blue.po.system.SyncFailDetailPO;
import com.blue.dto.system.SyncFailDetailDTO;
import com.blue.service.system.ISyncFailDetailService;
import com.blue.common.entity.ResponseResult;

import java.util.List;


/**
 * 数据同步失败明细表
 *
 * @author nanjie.chen
 * @email 15696271158@163.com
 * @date 2025-01-21
 */
@RestController
@RequestMapping("/system/syncFailDetail")
@Tag(name = "数据同步失败明细表")
public class SyncFailDetailController {
    @Autowired
    private ISyncFailDetailService syncFailDetailService;

    @GetMapping("/pageList")
    @Operation(summary = "列表查询")
    public ResponseResult<?> list(SyncFailDetailDTO requestDTO,
                                  @RequestParam(value = "pageSize", defaultValue = "10") long pageSize,
                                  @RequestParam(value = "pageNum", defaultValue = "1") long pageNum){
        SyncFailDetailPO syncFailDetailPO = ConvertUtils.convert(SyncFailDetailPO.class, requestDTO);
        MPJQueryWrapper<SyncFailDetailPO> queryWrapper = QueryWrapperUtils.initQueryWrapper(syncFailDetailPO);
        Page<SyncFailDetailPO> page = new Page<>(pageNum, pageSize);
        Page<SyncFailDetailPO> pageResult = syncFailDetailService.page(page, queryWrapper);
        return ResponseResult.okResult(pageResult);
    }

    @PostMapping("/add")
    @Operation(summary = "新增")
    public ResponseResult<?> add(@RequestBody SyncFailDetailDTO requestDTO) {
        SyncFailDetailPO syncFailDetailPO = ConvertUtils.convert(SyncFailDetailPO.class, requestDTO);
            syncFailDetailService.save(syncFailDetailPO);
        return ResponseResult.okResult();
    }

    @PostMapping("/edit")
    @Operation(summary = "修改")
    public ResponseResult<?> edit(@RequestBody SyncFailDetailDTO requestDTO) {
        SyncFailDetailPO syncFailDetailPO = ConvertUtils.convert(SyncFailDetailPO.class, requestDTO);
        syncFailDetailService.updateById(syncFailDetailPO);
        return ResponseResult.okResult();
    }

    @PostMapping("/delete")
    @Operation(summary = "删除")
    public ResponseResult<?> delete(@RequestBody List<String> ids) {
        syncFailDetailService.removeBatchByIds(ids);
        return ResponseResult.okResult();
    }

    @PostMapping("/queryById")
    @Operation(summary = "通过ID查询")
    public ResponseResult<?> queryById(@RequestBody SyncFailDetailDTO requestDTO) {
        SyncFailDetailPO syncFailDetailPO = syncFailDetailService.getById(requestDTO.getId());
        return ResponseResult.okResult(syncFailDetailPO);
    }
}
